PhpUnit 模拟 : function undefined
全部标签 classTestMe{publicfunctionmethod(){}}测试:classTestTestextendsPHPUnit_Framework_TestCase{publicfunctiontestA(){$stub=$this->getMock('TestMe');$stub->expects($this->exactly(2))->method('method');}publicfunctiontestB(){$stub=$this->getMock('TestMe');$stub->expects($this->exactly(2))->method('method'
我正在尝试测试一个简单的类。我正在学习本教程(http://code.tutsplus.com/tutorials/testing-laravel-controllers--net-31456)。我在运行测试时遇到这个错误:MethodMockery_0_App_Interfaces_MealTypeRepositoryInterface::getValidator()doesnotexistonthismockobject我正在使用存储库结构。因此,我的Controller调用存储库并返回Eloquent的响应。我是php和laravel的新手。而且我几天前就开始学习测试了,所以对于
我正在使用PHPUnit测试一个下载文件的函数。我想测试是否下载了正确的文件,所以我的想法是检查函数的输出。我正在尝试使用输出缓冲:ob_start();$viewer->downloadById($fileId);$output=ob_get_flush();$this->assertEquals($expectedFileContents,$output);测试在应该通过/失败的时候通过/失败,这很好。我的问题是输出缓冲区的内容也打印到控制台。我该如何隐藏它? 最佳答案 使用ob_get_clean()而不是ob_get_flu
在我的symfony2应用程序中,我使用phpunit来测试每个Controller的Action响应的状态代码是否是预期的。如果不是,我如何让phpunit显示异常附带的错误消息,或者最好模拟一个探查器异常页面?这是因为我在phpunit中有一个返回500代码的操作,但它在我的浏览器中加载得很好。我的代码:/***@dataProviderurlProvider*@param$url*/publicfunctiontestPageIsSuccessful($url){$client=self::createClient(array(),array('PHP_AUTH_USER'=>'
我正在用symfony2做一些PHPUnit测试。我在一项特定测试中遇到问题。我正在测试我类(class)之一的回应,当然一个回应是对的,一个是错的。我有一个我的数据库的模拟,并且我有一个来self的databaseRepository的方法的stub。问题是,在一个测试中,我对具有有效数组的方法进行了stub,在第二个测试中,我只想查询无效的null。我的数据库模拟://Settingupmockofdatabaserepositoryclass$this->db=$this->getMockBuilder('DatabaseRepository')->disableOriginal
我创建了一个View助手:classSousMenuContratextendsAbstractHelper{private$maiContratService;publicfunction__construct(FMaiContratService$maiContratService,){$this->maiContratService=$maiContratService;}publicfunction__invoke($iMaiContratId,$sActive){$oContrat=$this->maiContratService->selectById($iMaiContr
我的xml文件中有以下内容,但它没有跳过第二个文件:./app/tests/./app/tests/unit/1.php./app/tests/unit/2.php 最佳答案 我建议你使用phpunitgroupannotation用于标记类/方法并将该组标记为从主测试套件中排除。你可以阅读thisarticle作为进一步的引用。例如,您可以在测试类中执行以下操作:class1extendsPHPUnit_Framework_TestCase{/***@groupexcludeMe*/publicfunctiontestSometh
在单元测试方法中,我尝试像这样模拟Cache::remember响应:Cache::shouldReceive('remember')->once()->with('my_key',120,function(){})//Thereare3argsinremembermethod->andReturn([]);但是我得到这个错误:exception'Mockery\Exception\NoMatchingExpectationException'withmessage'NomatchinghandlerfoundforMockery_0_Illuminate_Cache_CacheMan
Laravel版本5.2在我的项目中,role_id=4的用户具有admin角色,可以管理用户。我在AuthServiceProvider中定义了以下能力:publicfunctionboot(GateContract$gate){$this->registerPolicies($gate);$gate->define('can-manage-users',function($user){return$user->role_id==4;});}我已经在UserController__construct方法中使用了这种能力,如下所示:publicfunction__construct()
我有一个被多个类使用的特征,即classSomeClass{useTimeoutTrait;functionhandle(){$this->traitFunction()//canthisbemocked?}}PHP单元能够模拟traitFunction()吗?在此先感谢您的帮助。问候 最佳答案 Traits是代码容器,编译器将代码“复制粘贴”到您要在其中使用它的类中,从而使其可在全世界重用。一般来说,单元测试中的特征函数没有什么特别的,因为。当类被实例化时,trait函数与可以正确复制粘贴的函数没有任何区别,它们是在类中的trai